﻿using HKSdkLibrary;
using OSSUtility;
using Ozone.Device;
using Rubyer;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using static NPOI.HSSF.Util.HSSFColor;

namespace Ozone.Views.Video
{
    /// <summary>
    /// UCVideoMonitor.xaml 的交互逻辑
    /// </summary>
    public partial class UCVideoMonitor : UserControl
    {
        public UCVideoMonitor()
        {
            InitializeComponent();
        }
        public void TagC(string sTitle, int nTagNum)
        {
            lblTitle.Content = sTitle;
            btnBigVideo.Tag = "Big" + nTagNum;
            btnCapture.Tag = "Cap" + nTagNum;
            btnBack.Tag = "Back" + nTagNum;
            btnLeft.Tag = "left" + nTagNum;
            btnRight.Tag = "right" + nTagNum;
            btnUp.Tag = "up" + nTagNum;
            btnDown.Tag = "down" + nTagNum;
        }
        private void btnCapture_Click(object sender, RoutedEventArgs e)
        {
            string sTag = ((Button)sender).Tag.ToString();
            CamCapture(sTag);
        }

        private void btnBackVideo_Click(object sender, RoutedEventArgs e)
        {
            string sTag = ((Button)sender).Tag.ToString();
            CamBackView(sTag);
        }

        private void btnBigVideo_Click(object sender, RoutedEventArgs e)
        {
            string sTag = ((Button)sender).Tag.ToString();
            CamBigView(sTag);
        }
        private void btn_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            string tag = ((Button)sender).Tag.ToString();
            CamMove(tag, 0);
        }
        private void btn_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            string tag = ((Button)sender).Tag.ToString();
            CamMove(tag, 1);
        }
        //移动
        private void CamMove(string MoveType, uint isstop)
        {
            string sType = MoveType.Substring(0, MoveType.Length - 1);
            int nMoveNum = Utility.str2int(MoveType.Substring(MoveType.Length - 1, 1));
            DeviceCenter.Entity.hKCams[nMoveNum - 1].CamMoveLURD(sType, nMoveNum,isstop);
        }
        //放大
        private void CamBigView(string Big)
        {
            string sType = Big.Substring(0, Big.Length - 1);
            int nBigNum = Utility.str2int(Big.Substring(Big.Length - 1, 1));
            BigVideoWindow bigVideoWindow = new BigVideoWindow();
            bigVideoWindow.ShowBigVideo(DeviceCenter.Entity.VideoIPs[nBigNum-1], DeviceCenter.Entity.VideoPasswords[nBigNum-1], DeviceCenter.Entity.VideoTitles[nBigNum-1], DeviceCenter.Entity.hKCams[nBigNum-1], nBigNum);
            bigVideoWindow.ShowDialog();
        }
        //回放
        private void CamBackView(string Back)
        {
            string sType = Back.Substring(0, Back.Length - 1);
            int nBackNum = Utility.str2int(Back.Substring(Back.Length - 1, 1));
            BackVideoWindow backVideoWindow = new BackVideoWindow(DeviceCenter.Entity.hKCams[nBackNum-1].m_userID, DeviceCenter.Entity.hKCams[nBackNum-1]);
            backVideoWindow.ShowDialog();
        }
        //拍照
        private void CamCapture(string Cap)
        {
            string sType = Cap.Substring(0, Cap.Length - 1);
            int nCapNum = Utility.str2int(Cap.Substring(Cap.Length - 1, 1));
            string fileAddress = DeviceCenter.Entity.hKCams[nCapNum-1].hKSdkMethods.CapturePictures(ConfigurationManager.AppSettings["CaptureAddress"].ToString(), DeviceCenter.Entity.hKCams[nCapNum-1].m_userID, out DeviceCenter.Entity.hKCams[nCapNum-1].ErrorMessage);
            MessageBox.Show(fileAddress);
        }
    }
}
